package com.tfjybj.itoo.exam.provider.service.impl;

import com.dmsdbj.itoo.tool.base.service.impl.BaseServicePlusImpl;
import com.dmsdbj.itoo.tool.redis.CacheExpire;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.QuestionTypeEntity;
import com.tfjybj.itoo.exam.model.EvaluationTypeModel;
import com.tfjybj.itoo.exam.model.QuestionTypeIdModel;
import com.tfjybj.itoo.exam.model.QuestionTypeModel;
import com.tfjybj.itoo.exam.provider.dao.QuestionTypeDao;
import com.tfjybj.itoo.exam.provider.service.QuestionTypeService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * QuestionTypeService接口实现类
 * ${base}表
 *
 * @author 郭凯
 * @version 2.0.0
 * @since 2.0.0 2018-11-21 21:10:06
 */
@Service("questionTypeService")
public class QuestionTypeServiceImpl extends BaseServicePlusImpl<QuestionTypeDao, QuestionTypeEntity> implements QuestionTypeService {

    //region 模板生成
    @Resource
    private QuestionTypeDao questionTypeDao;

    @Override
    public PageInfo<QuestionTypeEntity> queryByLikeQuestionTypeName(String questionTypeName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(questionTypeDao.queryLikeQuestionTypeName(questionTypeName));
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */


//    /**
//     * 查询所有题型信息
//     *
//     * @return 所有题型信息/给前端用的
//     * @author 樊建华
//     * @since 2018年11月22日08:55:15
//     */
//
//    public List<QuestionTypeEntity> selectByExample(){
//        List<QuestionTypeEntity> questionTypeEntityList = new ArrayList<>();
//          questionTypeEntityList = questionTypeDao.queryAll();
//          return questionTypeEntityList;
//    }

    @Cacheable(value = "queryAllQuestionType", unless = "#result == null  || #result.size()==0")
    @CacheExpire(expire = 120)
    @Override
    public List<QuestionTypeModel> queryAllQuestionType() {
        return questionTypeDao.queryAllQuestionType();
    }

    @Override
    public List<EvaluationTypeModel> queryEvaluationAllQuestionType() {
        return questionTypeDao.queryEvaluationAllQuestionType();
    }

    @Override
    public String queryByCode(String code) {
        return questionTypeDao.queryByCode(code);
    }


    /**
     * 课程练习-根据课程id查询题型
     *
     * @param courseId
     * @return 是否查询成功
     * @author 贾建清
     * @since 2.0.0 2019年3月24日10:37:00
     */
    @Override
    public List<QuestionTypeIdModel> queryQuestionType(String courseId) {
        return questionTypeDao.queryQuestionType(courseId);
    }

}
